/*
 * @Author: Zhangxx 2425792130@qq.com
 * @Date: 2024-07-01 11:02:29
 * @LastEditors: Zhangxx 2425792130@qq.com
 * @LastEditTime: 2024-07-01 16:28:22
 * @FilePath: \geek-pc\src\store\login.Store.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 登录模块
import { makeAutoObservable } from "mobx"
import { http,getToken,setToken,removeToken } from '../utils'

class LoginStore {
  token = getToken() ||''
  constructor() {
    makeAutoObservable(this)
  }
  // 登录
  login = async ({ mobile, code }) => {
    const res = await http.post('http://geek.itheima.net/v1_0/authorizations', {
      mobile,
      code
    })
    this.token = res.data.token
    setToken(res.data.token)
  }
  // 退出登录
  loginOut = () => {
    this.token = ''
    removeToken()
  }
}
export default LoginStore